/*    */ package com.infoservice.schedule.generator;
/*    */ 
/*    */ import com.infoservice.po3.core.context.POContext;
/*    */ import com.infoservice.po3.core.exceptions.DAOException;
/*    */ import com.infoservice.schedule.ScheduleException;
/*    */ import com.infoservice.schedule.po.ScheduleDao;
/*    */ import com.infoservice.schedule.po.pos.TaskPO;
/*    */ import java.util.Hashtable;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ import java.util.Map.Entry;
/*    */ import org.apache.log4j.Logger;
/*    */ 
/*    */ public class TaskMng
/*    */ {
/* 36 */   private Logger logger = Logger.getLogger(TaskMng.class);
/*    */ 
/* 38 */   private Map<Long, TaskTimer> timerMap = new Hashtable();
/* 39 */   private static TaskMng taskMng = null;
/*    */ 
/*    */   public static TaskMng getInstance()
/*    */   {
/* 44 */     if (taskMng == null) {
/* 45 */       taskMng = new TaskMng();
/*    */     }
/* 47 */     return taskMng;
/*    */   }
/*    */ 
/*    */   public void remove(long taskInfoId) {
/* 51 */     ((TaskTimer)this.timerMap.get(Long.valueOf(taskInfoId))).remove();
/*    */   }
/*    */   public void removeTaskPlan(long taskId, long planId) {
/* 54 */     ((TaskTimer)this.timerMap.get(Long.valueOf(taskId))).removeTask(planId);
/*    */   }
/*    */   public void destory() {
/* 57 */     if (this.timerMap.isEmpty())
/* 58 */       return;
/* 59 */     for (Map.Entry entry : this.timerMap.entrySet()) {
/* 60 */       ((TaskTimer)entry.getValue()).cancel();
/*    */     }
/* 62 */     this.logger.info("Out TaskMng destory");
/*    */   }
/*    */   public void init() {
/* 65 */     this.logger.info("start TaskMng init...");
/*    */     try
/*    */     {
/* 68 */       List tpLi = ScheduleDao.loadAllTaskPlanInfo();
/* 69 */       if ((tpLi != null) && (tpLi.size() > 0)) {
/* 70 */         for (TaskPlanInfo tp : tpLi) {
/* 71 */           this.logger.info("任务计划编号=" + tp.getPlanId() + ",计划重复类型=" + tp.getPlanRepeatType());
/* 72 */           long taskId = tp.getTaskId().longValue();
/* 73 */           if (!this.timerMap.containsKey(Long.valueOf(taskId))) {
/* 74 */             this.timerMap.put(Long.valueOf(taskId), new TaskTimer("ScheduleTimer-" + tp.getPlanRepeatType() + "-" + tp.getTaskId().toString()));
/*    */           }
/* 76 */           TaskPO tk = ScheduleDao.loadTaskPoByTiTpID(taskId, tp.getPlanId().longValue());
/*    */ 
/* 78 */           TaskGenerator task = null;
/* 79 */           if (tp.getPlanRepeatType().equals("MINUTE")) {
/* 80 */             task = new GenMinTask(tp, tk);
/* 81 */           } else if (tp.getPlanRepeatType().equals("HOUR")) {
/* 82 */             task = new GenHourTask(tp, tk);
/* 83 */           } else if (tp.getPlanRepeatType().equals("DAY")) {
/* 84 */             task = new GenDayTask(tp, tk);
/* 85 */           } else if (tp.getPlanRepeatType().equals("WEEK")) {
/* 86 */             task = new GenWeekTask(tp, tk);
/* 87 */           } else if (tp.getPlanRepeatType().equals("MONTH")) {
/* 88 */             task = new GenMonthTask(tp, tk);
/* 89 */           } else if (tp.getPlanRepeatType().equals("YEAR")) {
/* 90 */             task = new GenYearTask(tp, tk); } else {
/* 91 */             if (tp.getPlanRepeatType().equals("ONLYONE")) {
/* 92 */               if (tk != null) {
/*    */                 continue;
/*    */               }
/* 95 */               task = new GenOnlyOneTask(tp, tk);
/* 96 */               task.fixTask();
/* 97 */               ((TaskTimer)this.timerMap.get(Long.valueOf(taskId))).addOnlyOneTaskGen(task);
/* 98 */               continue;
/*    */             }
/*    */ 
/* 101 */             throw new ScheduleException(null, "not support " + tp.getPlanRepeatType() + " repeat type", null);
/*    */           }
/* 103 */           task.fixTask();
/* 104 */           ((TaskTimer)this.timerMap.get(Long.valueOf(taskId))).addTaskGen(task);
/*    */         }
/*    */       }
/* 107 */       POContext.endTxn(true);
/* 108 */       this.logger.info("start TaskMng init success!");
/*    */     } catch (DAOException e) {
/* 110 */       POContext.endTxn(false);
/* 111 */       this.logger.error(e.getMessage(), e);
/*    */     } catch (Exception e) {
/* 113 */       POContext.endTxn(false);
/* 114 */       this.logger.error(e.getMessage(), e);
/*    */     } finally {
/* 116 */       POContext.cleanTxn();
/*    */     }
/*    */   }
/*    */ }

/* Location:           D:\Workspace\Work\ASMP_DE\lib\frame3\InfoSchedule_1.0.03.jar
 * Qualified Name:     com.infoservice.schedule.generator.TaskMng
 * JD-Core Version:    0.6.0
 */